﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace StorageBox
{
    /// <summary>
    /// 这里是背板[不再限制于ReaderBase的基类][需要单独创建]
    /// </summary>
    public class BackplaneReader
    {
        private static BackplaneReader _backplaneReader;
        private Grid _backplaneElement;
        private MainWindow _mainWindow;
        private Action _hideAction;

        public BackplaneReader(MainWindow main)
        {
            _backplaneReader = this;
            _mainWindow = main;
            _backplaneElement = main.Backplane;
        }

        public static void Show(Action hideAction, int Milliseconds = 500)
        {
            _backplaneReader._backplaneElement.Visibility = System.Windows.Visibility.Visible;
            _backplaneReader._hideAction = hideAction;
            SY_Library.Animate.Begin<DoubleAnimation, double>(_backplaneReader._backplaneElement, Grid.OpacityProperty, _backplaneReader._backplaneElement.Opacity, 1, Milliseconds);
        }

        public static void Hide(int Milliseconds = 500)
        {
            if (_backplaneReader._hideAction != null)
            {
                _backplaneReader._hideAction();
            }
            SY_Library.Animate.Begin<DoubleAnimation, double>(_backplaneReader._backplaneElement, Grid.OpacityProperty, _backplaneReader._backplaneElement.Opacity, 0, Milliseconds);
            Task.Run(() =>
            {
                Task.Delay(Milliseconds + 100).Wait();
                _backplaneReader._backplaneElement.Dispatcher.Invoke(() => { _backplaneReader._backplaneElement.Visibility = System.Windows.Visibility.Hidden; });
            });
        }
    }
}
